librarian::shelf(Seurat,
                 tidyseurat,
                 tidyverse,
                 harmony,
                 data.table,
                 readxl)

cell_meta <- read_csv('Archive/covid19/data/ren_zhang2021/GSE158055_cell_annotation.csv.gz')

cell_meta |>
  count(majorType)

cell_meta |>
  filter(majorType == "B") |>
  count(celltype)

cell_meta |>
  filter(majorType %in% c('B','Plasma')) |>
  count(celltype)

sample_meta <- 
  read_excel('Archive/covid19/data/ren_zhang2021/GSE158055_sample_metadata.xlsx',
             skip = 20)

sample_tidy <- sample_meta |> head(284)

sample_tidy |>
  write_csv('Archive/covid19/data/ren_zhang2021/sample.meta.csv')

sample_tidy |>
  colnames() |>
  str_remove('characteristics: ') |>
  str_squish() |>
  set_names(sample_tidy, nm = _) |>
  as_tibble(.name_repair = 'universal') |>
  write_csv('Archive/covid19/data/ren_zhang2021/sample.meta.csv')

long_mtx <- fread('~/learn/scvelo/data/ren2021/matrix.mtx.gz', skip = 3, verbose = T, nrows = 1e9)
colnames(long_mtx)
.Machine$integer.max

long_mtx

features <- read_tsv('~/learn/scvelo/data/ren2021/features.tsv.gz', col_names = 'symbol')

features |>
  mutate(id = symbol, type = 'gex') |>
  write_tsv('~/learn/scvelo/data/ren2021/features.new.tsv.gz', col_names = FALSE)

reticulate::use_condaenv('scvelo-e')
reticulate::repl_python()

# import scanpy as sc
# mtx = sc.read_10x_mtx('/home/gjsx/learn/scvelo/data/ren2021/',cache=True)
